<template>
<view>
	<view class="avatar">
	    <image :src="avatar"></image>
	</view>
	<view class="content" v-if="role == 2">
	    <input class="phoneinput" v-model="shopNum" placeholder="输入店铺编号"/>
	    <button v-if="addTrue" @click="binding" class="strue">绑定店铺</button>
		<button v-else class="strue">绑定店铺</button>
	</view>
	<view class="content" v-if="role == 3">
	    <button v-if="addTrue" @click="Opening" class="strue">申请开通</button>
		<button v-else class="strue">申请开通</button>
	</view>
</view>
</template>

<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			avatar:uni.getStorageSync('avatarUrl'),
			role:0,
			shopNum:'',
			addTrue:true
		}
	},
	onLoad(e){
		this.role = uni.getStorageSync('role')
	},
	methods: {
		binding:function(){
			if(!this.shopNum){
				uni.showToast({
					title:'请输入店铺编号',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
			var data = {
				'uid':uni.getStorageSync('uid'),
			    'num':this.shopNum,
			}
			this.addTrue = false
			var that = this
			request({
				url: '/manage/user/login',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.showToast({
							title:'绑定成功',
							icon: 'none',
							duration: 2000,
							success() {
								setTimeout(function() {
									uni.navigateTo({
										url:'/manage/index'
									});
								}, 2000);
							}
						})
					}else{
						that.addTrue = false
						uni.showToast({
							title: res.data.msg,
							icon: "none", 
							position:'bottom',
						});
						return;
					}
				},
			})
		},
		Opening:function(){
			var data = {
				'uid':uni.getStorageSync('uid')
			}
			var that = this
			this.addTrue = false
			request({
				url: '/manage/company/login',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						wx.navigateTo({
						  uni:'/manage/index'
						})
					}
				},
			})
		}
	}
}
</script>

<style>
.avatar{
	background: #ff861a;
	width:100%;height:100px;
	display: flex;
	justify-content:center;
}
.avatar image{
	width:80px;height:80px;
	border-radius: 50%;
	margin-top:10px;
}
.content{
    margin-top:50rpx;
    width:100%;
    display:flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.phoneinput{
	width:70%;
	border:1rpx solid #333;
	height:70rpx;
	border-radius: 20rpx;
	padding-left:20rpx;
}
.strue{
    width:70%;height:70rpx;
    line-height:70rpx;
    margin-top:20rpx;
    background:#ff861a;color:#fff;
    font-size:12px;
}
</style>
